// JavaScript Document
function getByClass(oParent,sClass){
	var aEle=oParent.getElementsByTagName("*");
	var aTemp=[];
	for(n in aEle){
		if(aEle[n].className==sClass){
			aTemp.push(aEle[n]);	
		}
	}
	return aTemp;
}

function getElementsByClassName(className,oBox) {
	var o = document.getElementById(oBox) || document;
	var children = o.getElementsByTagName('*');
	var cs = new Array();
	for (var j= 0; j < children.length; j++) {
		var child = children[j];
		var classNames = child.className.split(' ');
		for (var k = 0; k < classNames.length; k++) {
			if (classNames[k] == className) {
				cs.push(child);
				break;
			}
		}
	}
	return cs;
}

//function bindEvent(elem,type,fn){
//    if(elem.attachEvent){
//        elem.attachEvent("on"+type,function(){
//            fn.apply(elem,arguments);
//        });
//    }else{
//        elem.addEventListener(type,fn,false);
//    }
//}

//绑定事件
function bindEvent(elem,type,fn){
    if(elem.attachEvent){
        var typeRef = "_" + type;
        if(!elem[typeRef]){
            elem[typeRef] = [];
        }
        for(var i in elem[typeRef]){
            if(elem[typeRef][i] == fn){
                return;
            }
        }
        elem[typeRef].push(fn);
        elem["on"+type] = function(){
            for(var i in this[typeRef]){
                this[typeRef][i].apply(this,arguments);
            }
        }   
    }else{
        elem.addEventListener(type,fn,false);
    }
}

//移除事件绑定
function removeEvent(elem,type,fn){
    if(elem.detachEvent){
        if(elem["_"+type]){
            for(var i in elem["_"+type]){
                if(elem["_"+type][i] == fn){
                    elem["_"+type].splice(i,1);
                    break;
                }
            }
        }
    }else{
        elem.removeEventListener(type,fn,false);
    }
}

